home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / J A V A / Java Development Kit V1.2 / jdk12-win32(1).exe / data1.cab / demos / demo / jfc / Metalworks / MetalThemeMenu.java < prev    next >
Encoding:
Java Source  |  1998-12-01  |  1.6 KB  |  61 lines

  1. /*
  2.  * @(#)MetalThemeMenu.java    1.4 98/08/26
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15.  
  16. import javax.swing.plaf.metal.*;
  17. import javax.swing.*;
  18. import javax.swing.border.*;
  19. import java.awt.*;
  20. import java.awt.event.*;
  21.  
  22. /**
  23.  * This class describes a theme using "green" colors.
  24.  *
  25.  * @version 1.4 08/26/98
  26.  * @author Steve Wilson
  27.  */
  28. public class MetalThemeMenu extends JMenu implements ActionListener{
  29.  
  30.   MetalTheme[] themes;
  31.   public MetalThemeMenu(String name, MetalTheme[] themeArray) {
  32.     super(name);
  33.     themes = themeArray;
  34.     ButtonGroup group = new ButtonGroup();
  35.     for (int i = 0; i < themes.length; i++) {
  36.         JRadioButtonMenuItem item = new JRadioButtonMenuItem( themes[i].getName() );
  37.     group.add(item);
  38.         add( item );
  39.     item.setActionCommand(i+"");
  40.     item.addActionListener(this);
  41.     if ( i == 0)
  42.         item.setSelected(true);
  43.     }
  44.  
  45.   }
  46.  
  47.   public void actionPerformed(ActionEvent e) {
  48.     String numStr = e.getActionCommand();
  49.     MetalTheme selectedTheme = themes[ Integer.parseInt(numStr) ];
  50.     MetalLookAndFeel.setCurrentTheme(selectedTheme);
  51.     try {
  52.     UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
  53.     } catch (Exception ex) {
  54.         System.out.println("Failed loading Metal");
  55.     System.out.println(ex);
  56.     }
  57.  
  58.   }
  59.  
  60. }
  61.